1
|
|
|
const { globalShortcut, BrowserWindow } = require('electron'); |
2
|
|
|
|
3
|
|
|
module.exports = class Window { |
4
|
|
|
constructor(app) { |
5
|
|
|
|
6
|
|
|
this.app = app; |
7
|
|
|
|
8
|
|
|
// Load screen data |
9
|
|
|
const { screen } = require('electron'); |
10
|
|
|
|
11
|
|
|
// Create Window |
12
|
|
|
const win = this.win = new BrowserWindow({ |
|
|
|
|
13
|
|
|
width: screen.getPrimaryDisplay().workAreaSize.width, |
14
|
|
|
height: screen.getPrimaryDisplay().workAreaSize.height, |
15
|
|
|
show: false, |
16
|
|
|
simpleFullscreen: true, |
17
|
|
|
icon: app.icon |
18
|
|
|
}); |
19
|
|
|
|
20
|
|
|
// Always allow opening dev tools in any build or platform |
21
|
|
|
// In production the dev tools menu item will be removed but the dev tools |
22
|
|
|
// themselves will always be openable with the same shortcut. |
23
|
|
|
// This means your average user won't have to concern over it but developers |
24
|
|
|
// or tinkerers can still access it if desired |
25
|
|
|
globalShortcut.register('CommandOrControl+Shift+I', this.toggleDevTools.bind(this)); |
|
|
|
|
26
|
|
|
|
27
|
|
|
// Load contents depending on development enviroment or not |
28
|
|
|
if (app.isDev) |
29
|
|
|
win.loadURL('http://localhost:4200'); |
|
|
|
|
30
|
|
|
else |
31
|
|
|
win.loadFile('./dist/pokered-save-editor/index.html'); |
32
|
|
|
|
33
|
|
|
// Hook into events |
34
|
|
|
win.on('closed', this.onClosed.bind(this)); |
35
|
|
|
win.once('ready-to-show', this.onReadyToShow.bind(this)); |
36
|
|
|
app.on('ipcTo', this.onIpcTo.bind(this)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// Certain events can be hooked into and echoed to the ipcTo channel |
40
|
|
|
// which will be relayed directly to the window |
41
|
|
|
relayTo(event, ...args) { |
42
|
|
|
app.emit(`ipcTo`, event, ...args); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
toggleDevTools() { |
46
|
|
|
this.win.webContents.toggleDevTools(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
reOpen() { |
50
|
|
|
if (this.win.isMinimized()) this.win.restore(); |
|
|
|
|
51
|
|
|
this.win.focus(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
onIpcTo(event, ...args) { |
55
|
|
|
|
56
|
|
|
const appName = this.app.app.getName(); |
57
|
|
|
|
58
|
|
|
// Jump in on certain events |
59
|
|
|
if (event === "pathChange" && args[0] !== "") |
60
|
|
|
this.win.setTitle(`${appName} - ${args[0]}`); |
|
|
|
|
61
|
|
|
else if (event === "pathChange") |
62
|
|
|
this.win.setTitle(`${appName} - New File`); |
|
|
|
|
63
|
|
|
|
64
|
|
|
this.win.webContents.send(event, ...args); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
onClosed() { |
68
|
|
|
this.win = null; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
onReadyToShow() { |
72
|
|
|
this.win.show(); |
73
|
|
|
this.app.emit("window-ready"); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.